/*
 * File Name:               CDelayTimer.cs
 *
 * Description:             延迟计时
 * Author:                  lisiyu <576603306@qq.com>
 * Create Date:             2016/11/18
 */

using System;
using System.Collections.Generic;

public class CDelayTimer : ICache, IComparer<CDelayTimer>
{
    private object mArgs;

    public Action<object> pCallback;
    public ulong pUid;
    public float pExcuteTime;
    public bool alive;

    public void onSpawn(object args)
    {
        mArgs = args;
        alive = true;
    }

    public void onRecycle()
    {
        mArgs = null;
        pCallback = null;
        //alive = false;
    }

    public void setCallback(Action<object> callback)
    {
        pCallback = callback;
    }

    public void setUid(ulong uid)
    {
        pUid = uid;
    }

    public void excute()
    {
        pCallback(mArgs);
        alive = false;
    }

    public int Compare(CDelayTimer x, CDelayTimer y)
    {
        if (x.pExcuteTime < y.pExcuteTime)
            return -1;

        if (x.pExcuteTime > y.pExcuteTime)
            return 1;

        return 0;
    }
}